ga.core.algorithm.interactive
Class AbstractSIGA<T extends IIndividual<T>>

java.lang.Object
  extended by ga.core.algorithm.interactive.AbstractSIGA<T>
Type Parameters:
T - The generic type of individuals.
All Implemented Interfaces:
ISIGA<T>, EvaluationListener<T>, GA<T>
Direct Known Subclasses:
SIGA, SIGAGeneration

public abstract class AbstractSIGA<T extends IIndividual<T>>
extends java.lang.Object
implements ISIGA<T>

Abstract class for an simple interactive genetic algorithm.

Since:
11.08.2012
Author:
Stephan Dreyer

Field Summary
private  java.lang.Thread accessThread
           
private  GAContext context
           
private  ICrossoverOp<T> crossoverOp
           
private  IndividualList<T> evaluatingIndividuals
           
private  IInteractiveFitnessEvaluator<T> evaluator
           
private  IGALogger<T> gaLogger
           
private  int generation
           
private static java.util.logging.Logger LOGGER
           
private  IMutationOp<T> mutationOp
           
private  IPopulation<T> population
           
private  ISelector<T> selector
           
private  boolean useEliteStrategy
           
private  boolean validate
           
private  IValidator<T> validator
           
 
Fields inherited from interface ga.core.GA
KEY_EVALUATED_INDIVIDUALS_MIN_COUNT, KEY_GENOME_MAX_LENGTH, KEY_GENOME_MIN_LENGTH, KEY_INIT_INDIVIDUAL, KEY_INIT_INDIVIDUAL_PERCENTAGE, KEY_INTERVAL_FITNESS_MAX_WIDTH, KEY_VALIDATION_SPACE
 
Constructor Summary
AbstractSIGA(IPopulation<T> population, IInteractiveFitnessEvaluator<T> evaluator, ISelector<T> selector, IMutationOp<T> mutateOperator, ICrossoverOp<T> crossoverOperator, IValidator<T> validator, boolean useEliteStrategy, IGALogger<T> gaLogger)
          Initializes the abstract class.
 
Method Summary
protected  void checkThread()
          Helper method to check if the current thread is the creation thread.
 void exit()
          Exits the algorithm and frees resources.
 GAContext getContext()
          Getter for the GA context.
 ICrossoverOp<T> getCrossoverOp()
          Getter for the crossover operator.
protected  IndividualList<T> getEvaluatingIndividuals()
          Getter for the list of individuals, that are currently being evaluated.
protected  IInteractiveFitnessEvaluator<T> getEvaluator()
          Getter for the evaluator.
protected  IGALogger<T> getGALogger()
          Getter for the ga logger.
 int getGeneration()
          Getter for the current generation.
 IMutationOp<T> getMutationOp()
          Getter for the mutation operator.
 IPopulation<T> getPopulation()
          Getter for the population.
protected  ISelector<T> getSelector()
          Getter for the selector.
protected  IValidator<T> getValidator()
          Getter for the validator.
protected  void incGeneration()
          Increments the current generation number.
 void init()
          Initializes the algorithm and population.
protected  boolean isUseEliteStrategy()
          Getter for the elite behavior.
protected  boolean isValidate()
          Getter for the validation behavior.
 void setValidate(boolean validate)
          Setter to enable/disable individual validation.
 void setValidator(IValidator<T> validator)
          Set the individual validator for the algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ga.core.algorithm.interactive.ISIGA
individualEvaluated, newIndividualRequested
 
Methods inherited from interface ga.core.GA
step
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

accessThread

private final java.lang.Thread accessThread

gaLogger

private final IGALogger<T extends IIndividual<T>> gaLogger

population

private final IPopulation<T extends IIndividual<T>> population

selector

private final ISelector<T extends IIndividual<T>> selector

evaluator

private final IInteractiveFitnessEvaluator<T extends IIndividual<T>> evaluator

mutationOp

private final IMutationOp<T extends IIndividual<T>> mutationOp

crossoverOp

private final ICrossoverOp<T extends IIndividual<T>> crossoverOp

validator

private IValidator<T extends IIndividual<T>> validator

context

private final GAContext context

evaluatingIndividuals

private final IndividualList<T extends IIndividual<T>> evaluatingIndividuals

validate

private boolean validate

useEliteStrategy

private final boolean useEliteStrategy

generation

private int generation
Constructor Detail

AbstractSIGA

public AbstractSIGA(IPopulation<T> population,
                    IInteractiveFitnessEvaluator<T> evaluator,
                    ISelector<T> selector,
                    IMutationOp<T> mutateOperator,
                    ICrossoverOp<T> crossoverOperator,
                    IValidator<T> validator,
                    boolean useEliteStrategy,
                    IGALogger<T> gaLogger)
Initializes the abstract class.

Parameters:
population - Population for the GA.
evaluator - The automatic evaluator.
selector - The selector.
mutateOperator - The mutation operator.
crossoverOperator - The crossover operator.
validator - The validator
useEliteStrategy - Use elite strategy or not.
gaLogger - The ga logger.
Since:
11.08.2012
Method Detail

init

public void init()
Description copied from interface: GA
Initializes the algorithm and population.

Specified by:
init in interface ISIGA<T extends IIndividual<T>>
Specified by:
init in interface GA<T extends IIndividual<T>>

checkThread

protected void checkThread()
Helper method to check if the current thread is the creation thread.

Since:
11.08.2012

getGALogger

protected IGALogger<T> getGALogger()
Getter for the ga logger. May only be called by subclasses.

Returns:
The ga logger.
Since:
11.08.2012

getSelector

protected ISelector<T> getSelector()
Getter for the selector. May only be called by subclasses.

Returns:
The selector.
Since:
11.08.2012

isUseEliteStrategy

protected boolean isUseEliteStrategy()
Getter for the elite behavior. May only be called by subclasses.

Returns:
true if should use elite strategy.
Since:
11.08.2012

getCrossoverOp

public ICrossoverOp<T> getCrossoverOp()
Description copied from interface: ISIGA
Getter for the crossover operator.

Specified by:
getCrossoverOp in interface ISIGA<T extends IIndividual<T>>
Returns:
Crossover operator.

getMutationOp

public IMutationOp<T> getMutationOp()
Description copied from interface: ISIGA
Getter for the mutation operator.

Specified by:
getMutationOp in interface ISIGA<T extends IIndividual<T>>
Returns:
Mutation operator.

getEvaluatingIndividuals

protected IndividualList<T> getEvaluatingIndividuals()
Getter for the list of individuals, that are currently being evaluated. May only be called by subclasses.

Returns:
List of evaluating individuals.
Since:
11.08.2012

isValidate

protected boolean isValidate()
Getter for the validation behavior. May only be called by subclasses.

Returns:
true if should validate individuals.
Since:
11.08.2012

getValidator

protected IValidator<T> getValidator()
Getter for the validator. May only be called by subclasses.

Returns:
The validator or null if not set.
Since:
11.08.2012

getEvaluator

protected IInteractiveFitnessEvaluator<T> getEvaluator()
Getter for the evaluator.

Returns:
The interactive fitness evaluator.
Since:
11.08.2012

setValidate

public void setValidate(boolean validate)
Description copied from interface: GA
Setter to enable/disable individual validation. To validate, this must be set to true and a validator must be set.

Specified by:
setValidate in interface ISIGA<T extends IIndividual<T>>
Specified by:
setValidate in interface GA<T extends IIndividual<T>>
Parameters:
validate - Enable/disable validation.

setValidator

public void setValidator(IValidator<T> validator)
Description copied from interface: GA
Set the individual validator for the algorithm. To validate, this must be not be null and validate must have been activated.

Specified by:
setValidator in interface ISIGA<T extends IIndividual<T>>
Specified by:
setValidator in interface GA<T extends IIndividual<T>>
Parameters:
validator - The individual validator.

getPopulation

public IPopulation<T> getPopulation()
Description copied from interface: GA
Getter for the population.

Specified by:
getPopulation in interface ISIGA<T extends IIndividual<T>>
Specified by:
getPopulation in interface GA<T extends IIndividual<T>>
Returns:
The population.

getContext

public GAContext getContext()
Description copied from interface: ISIGA
Getter for the GA context.

Specified by:
getContext in interface ISIGA<T extends IIndividual<T>>
Returns:
The GA context.

getGeneration

public int getGeneration()
Description copied from interface: ISIGA
Getter for the current generation. Note: in steady state mode, this is the actual number of single reproductions.

Specified by:
getGeneration in interface ISIGA<T extends IIndividual<T>>
Returns:
Current generation.

incGeneration

protected void incGeneration()
Increments the current generation number. May only be called by subclasses.

Since:
11.08.2012

exit

public void exit()
Description copied from interface: ISIGA
Exits the algorithm and frees resources.

Specified by:
exit in interface ISIGA<T extends IIndividual<T>>